package cn.wolfcode.wolf2w.note.controller;

import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.member.api.RemoteUserInfoService;
import cn.wolfcode.wolf2w.member.api.domain.UserInfo;
import cn.wolfcode.wolf2w.note.api.domain.Note;
import cn.wolfcode.wolf2w.note.query.NoteQuery;
import cn.wolfcode.wolf2w.note.service.INoteService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 旅游日记 Controller
 * 
 * @author dafei
 * @date 2023-11-25
 */
@RestController
@RequestMapping("notes")
public class NoteController {
    @Autowired
    private INoteService noteService;
    @Autowired
    private RemoteUserInfoService remoteUserInfoService;
    /**
     * 旅游日记详情
     */
    @GetMapping("/detail/{id}")
    public R<Note> detail(@PathVariable Long id) {
        Note note = noteService.getById(id);
        note.setContent(noteService.getContent(id));
        R<UserInfo> ret = remoteUserInfoService.getOne(note.getAuthorId(), SecurityConstants.INNER);
        if(ret != null && R.isSuccess(ret)){
            note.setAuthor(ret.getData());
        }
        return R.ok(note);
    }
    /**
     * 旅游日记 列表
     */
    @GetMapping("/query")
    public R<IPage<Note>> query(NoteQuery qo) {
        IPage<Note> page = noteService.queryPage(qo);
        return R.ok(page);
    }


    /**
     * 旅游日记 点击量前3
     */
    @GetMapping("/viewnnumTop3")
    public R<List<Note>> viewnnumTop3(Long destId) {
        List<Note> list = noteService.queryViewnumTop3(destId);
        return R.ok(list);
    }




    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Note>> feignList() {
        return R.ok(noteService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Note> feignGet(@PathVariable Long id) {
        return R.ok(noteService.getById(id));
    }
}
